package com.ruoyi.hr.service.impl;


import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.domain.CompanysRegister;
import com.ruoyi.hr.mapper.CompAdminMapper;
import com.ruoyi.hr.service.CompAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class CompAdminServiceImpl implements CompAdminService {

    @Autowired
    CompAdminMapper compAdminMapper;

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<CompanysRegister> getCompanysRegister(CompanysRegister companysRegister, List<Authority> authorities,int isAdmin) {
        return compAdminMapper.getCompanysRegister(companysRegister, authorities,isAdmin);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int findCount(CompanysRegister companysRegister, List<Authority> authorities) {
        return compAdminMapper.findCount(companysRegister, authorities);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int insertCompanysRegister(CompanysRegister companysRegister) {
        return compAdminMapper.insertCompanysRegister(companysRegister);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<List<Map<String, Object>>> executeProcedure(String sql) {
        return compAdminMapper.executeProcedure(sql);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public CompanysRegister getCompanysRegisterById(int id) {
        return compAdminMapper.getCompanysRegisterById(id);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int updateCompanysRegister(CompanysRegister companysRegister) {
        return compAdminMapper.updateCompanysRegister(companysRegister);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int deleteCompanysRegister(String ids) {
        return compAdminMapper.deleteCompanysRegister(ids);
    }

    @Override
    public String getRegByName(int userId) {
        return compAdminMapper.getRegByName(userId);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<CompanysRegister> getCompanysRegisterByIds(String ids) {
        return compAdminMapper.getCompanysRegisterByIds(ids);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int updateInvalidDate(String ids, String effectDate) {
        return compAdminMapper.updateInvalidDate(ids, effectDate);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<CompanysRegister> getCompanysRegisterByDate(String startDate, String endDate, List<Authority> authorities,int isAdmin) {
        List<CompanysRegister> companysRegisterList = compAdminMapper.getCompanysRegisterByDate(startDate, endDate, authorities,isAdmin);
        for (CompanysRegister companysRegister : companysRegisterList) {
            if (companysRegister.getType() == 1) {
                companysRegister.setTypeName("新增");
            } else if (companysRegister.getType() == 2) {
                companysRegister.setTypeName("变更");
            } else if (companysRegister.getType() == 3) {
                companysRegister.setTypeName("失效");
            }
        }
        return companysRegisterList;
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<CompanysRegister> getCompanysRegisterByProcedure(CompanysRegister companysRegister, List<Authority> authorities) {
        return compAdminMapper.getCompanysRegisterByProcedure(companysRegister,authorities);
    }
}
